﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;
using WPLDB.Infrastucture.UI.Events;
using WPLDB.DA.Models;
using Microsoft.Practices.Prism.Events;
using WPLDB.Infrastucture.UI.Models;
using System.ComponentModel.Composition;

namespace WPLDB.Infrastucture.UI.ViewModelBase
{

    /// <summary>
    /// This is the base class for all the viewModel classes, it has common properties and functions of viewModel.
    /// </summary>
    public class ViewModelBase : INotifyPropertyChanged
    {

        #region "Variables & Properties"
        public event PropertyChangedEventHandler PropertyChanged;

        [Import]
        private IEventAggregator _eventAggregator = null;

        public int Index
        {
            get;
            set;
        }

        #endregion

        #region "ctor"

        public void OnPropertyChanged<T>(Expression<Func<T>> expression)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(((MemberExpression)expression.Body).Member.Name));
            }
        }

        #endregion

        #region "Methods"

        public void RaiseEvent(string name)
        {
            if (null != _eventAggregator)
                _eventAggregator.GetEvent<ChooseViewChangedEvent<object>>().Publish(name);
        }

        #endregion

    }

}
